package com.slmxz.tms.common.util;

import com.slmxz.tms.common.enums.BizMessageEnum;
import com.slmxz.tms.core.handler.MessageSourceHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.MessageFormat;

/**
 * @Author：albert
 * @Date：2025/8/15 16:28
 */
@Component
public class I18nUtil {
    private static MessageSourceHandler messageSourceHandler;

    @Autowired
    public void setMessageSourceHandler(MessageSourceHandler messageSourceHandler) {
        I18nUtil.messageSourceHandler = messageSourceHandler;
    }

    public static String translate(BizMessageEnum bizMessageEnum, Object... args) {
        //进行国际化转化
        String messageText = messageSourceHandler.getMessage(bizMessageEnum.getCode());
        if(args != null && args.length > 0){
            messageText = MessageFormat.format(messageText, args);
        }
        return messageText;
    }
}
